﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="../lib/layui/css/layui.css" rel="stylesheet" />
    <link href="../lib/layui/lay/plugins/eleTree/font/eleTree.css" rel="stylesheet" />
    <script src="../lib/Base64/base64.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
    <script src="../linq.js/linq.js"></script>
    <script src="../lib/layui/layui.js"></script>
    <style>
        .layui-form-item .layui-input-inline {
            width: 280px;
        }
    </style>
</head>

<body style="background-color:#eee;">
    <div class="layui-fluid">
        <form class="layui-form" lay-filter="processPackagForm">
            <div class="layui-form-item" style="margin-top:10px;">
                <label class="layui-form-label">备注信息：</label>
                <div class="layui-input-block">
                    <input type="text" name="remark" id="remark" placeholder="请输入备注信息" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" style="height:400px;" >
                <label class="layui-form-label">案件类型：</label>
                <div class="layui-input-block" style="height:400px; overflow-y:auto;">
                    <div class="eleTree" id="caseTypeTree" lay-filter="caseTypeTree"></div>
                </div>
            </div>

            <div class="layui-form-item" style="text-align:center;">
                <a class="layui-btn"  href="javascript:;" lay-submit lay-filter="packag">提交</a>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }
        layui.config({
            base: '/lib/layui/lay/plugins/'
        }).extend({
            eleTree: 'eleTree/eleTree'
        }).use(['form', 'eleTree'], function () {
            var form = layui.form;
            var eleTree = layui.eleTree;
            var $ = layui.$;
            var el = eleTree({
                el: '#caseTypeTree',
                method: 'get',
                url: localStorage.getItem('hosttingaddr') + '/api/packag/getprocesstree',
                emptText: "暂无数据",
                showCheckbox: true,
                highlightCurrent: true,
                showLine: true,
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    dataName: 'data'
                },
                request: {
                    name: 'name',
                    key: 'id',
                    children: 'childrens',
                    checked: 'checked',
                    disabled: 'disabled',
                    isLeaf: 'isLeaf',
                    directory:'directory'
                }
            });
            form.on('submit(packag)', function (data) {
                data.elem.removeAttribute("lay-submit");
                data.field.PackagType = "1";
                var caseTypes = el.getChecked(true, false);
                var dirArry = new Array();
                if (caseTypes != null && caseTypes.length > 0) {
                    for (var i = 0; i < caseTypes.length; i++) {
                        dirArry.push(caseTypes[i].directory)
                    }
                    data.field.dirs = dirArry;
                    var i = layui.layer.load();
                    layui.$.ajax({
                        type: 'post',
                        url: localStorage.getItem('hosttingaddr') + '/api/Packag/packagfile',
                        headers: {
                            user: getCookie("userinfo"),
                            version: getCookie("version")
                        },
                        dataType: 'json',
                        contentType: 'application/json;charset=utf-8',
                        data: JSON.stringify(data.field),
                        success: function (re) {
                            layui.layer.close(i);
                            if (re.code == 0) {
                                layer.msg('正在打包，请稍等!', { icon: 1, time: 1000 });
                                parent.layui.table.reload('packagTable');
                                var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                                parent.layer.close(index);
                            }
                        },
                        error: function (data) {
                            layer.msg('打包失败!', { icon: 1, time: 1000 });
                            parent.layui.table.reload('packagTable');
                            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                            
                            parent.layer.close(index);
                        }
                    });
                }
                else {
                    layer.msg('至少选择一个打包案件流程', {});
                }

                data.elem.setAttribute("lay-submit", true);
                return false;
            });
        });



    </script>
</body>
</html>